package addon.w3.mdx.com;

import java.io.IOException;

import addon.w3.mdx.MDXCOM;
import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;

/**
struct {
		OBJ
		ASCII 	"KEVT"			// Actually a separate object
		long	ntrks;			// usually (1)
		0xFFFFFFFF
		long 	frames[ntrks];
	} events[nevts];
 * @author madjk
 *
 */
public class MDXEventCOM extends MDXCOM {
	MDXObject obj;
	String objName = null; //"KEVT"
	int ffff = -1;
	int ntrks = -1;
	int frames[];
	
	int size = 0;
		
	public String getTag() {
		return "EVTS:event";
	}
	
	public int getSize() {
		return size;
	}
	
	public void _decode(LEDataInputStream ins) throws IOException, MDXException {
		obj = new MDXObject();
		obj.decode(ins);
		byte temp[] = new byte[4];
		ins.read(temp);
		objName = new String(temp);
		ntrks = ins.readInt();
		ffff = ins.readInt(); //0xFFFFFFFF static
		frames = new int[ntrks];
		for (int i = 0; i < frames.length; i++) {
			frames[i] = ins.readInt();
		}
		//debug(obj.toString() + "\n"+ntrks);
		size = obj.nbytesi + 12 + 4*ntrks;
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("TAG : "+getTag());
		sb.append("\n\tOBJ : "+(obj == null ? false : obj.toString()) );
		sb.append("\n\tOBJNAME : "+objName);
		sb.append("\n\tNTRKS : "+ntrks);
		sb.append("\n\tFRAME[] : "+frames.length);
		return sb.toString();
	}

	@Override
	public boolean isImplicitTag() {
		// TODO Auto-generated method stub
		return false;
	}
}